﻿using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Prompts.Prompting.ViewModels;

namespace Prompts.Prompting.Controls
{
    public class MultiSelectListbox : ListBox
    {
        public MultiSelectListbox()
        {
            SelectionChanged += (s, e) =>
                {
                    Selections = new ObservableCollection<IPromptItem>(
                        ((ObservableCollection<object>) SelectedItems).Select(i => (IPromptItem) i));
                };
        }

        public IList Selections
        {
            get { return (IList) GetValue(SelectionsProperty); }
            set { SetValue(SelectionsProperty, value); }
        }

        public static DependencyProperty SelectionsProperty = DependencyProperty.Register(
            "Selections",
            typeof (IList),
            typeof (MultiSelectListbox),
            null);
    }
}